﻿@using NigiriClub.WebUI.Models
@model NigiriClub.WebUI.Models.News

<div class="blog-post">
    <div class="panel panel-primary">
        <div class="panel-body">
            <div class="row">
                <div class="blog-post-title col-md-10">@Model.Title</div>
                @if (User.Identity.IsAuthenticated)
                {
                    Account loggedIn = Account.GetAccount(User.Identity.Name);
                    if (loggedIn.PermissionId == 2 || loggedIn.Id == Model.OwnerId)
                    {
                    <div class="col-md-2 post-tools">
                        @using (Html.BeginForm("EditNews", "Home", routeValues: new { id = @Model.Id }))
                        {
                            @Html.AntiForgeryToken()
                            <button class="btn-transparent"
                                type="submit"
                                style="float: left">
                                <span class="glyphicon glyphicon-pencil"></span>
                            </button>
                        }
                        @using (Html.BeginForm("DeleteNews", "Home", routeValues: new { id = @Model.Id }))
                        {
                            @Html.AntiForgeryToken()
                            <button class="btn-transparent"
                                type="submit"
                                style="float: left">
                                <span class="glyphicon glyphicon-remove"></span>
                            </button>
                        }
                    </div>
                    }
                }
            </div>
            @Html.Raw(@Model.Body)
        </div>
        <div class="panel-footer">
            <p>
                Запись опубликована @Model.Date.ToShortDateString(),
                @Html.Action("ProfileLinkById", "Profile", new { id = @Model.OwnerId })
            </p>
            <p>
                Категория: @using (Entities db = new Entities())
                           {
                               string categoryName =
                                   db.Category.FirstOrDefault(c => c.Id == Model.CategoryId).Name;
                               @Html.ActionLink(categoryName, "Index",
                               new { category = categoryName })
                           }
            </p>
            <p>
                <ul class="list-inline">
                    <li>Тэги:</li>
                    @foreach (var tag in @Model.TagList)
                    {
                        <li>@Html.ActionLink(tag.Name, "Index", new { tag = tag.Name })</li>
                    }
                </ul>
            </p>
        </div>
    </div>
</div>

<script>
    $(document).ready(function () {

        $(".post-tools").hide();

        // Deleting an Individual Service
        $(".panel-body").hover(function () {
            $(this).find(".post-tools").fadeIn("fast");
        },
        function () {
            $(this).find(".post-tools").fadeOut("slow");
        });
    });
</script>
